﻿''' <summary>
''' An enumerator that can enumerate each of the records in a CSV table.
''' </summary>
Public Class CsvTableEnumerator
    Implements IEnumerator

    Private _file As CsvTable = Nothing

    Private _rowIndex As Integer = -1

    ''' <summary>
    ''' Initializes a new instance of the <see cref="CsvTableEnumerator" /> class.
    ''' </summary>
    ''' <param name="file">The file.</param>
    Friend Sub New(ByVal file As CsvTable)
        Me._file = file
    End Sub

    ''' <summary>
    ''' Gets the current element in the collection.
    ''' </summary>
    ''' <value></value>
    ''' <returns>The current element in the collection.</returns>
    ''' <exception cref="T:System.InvalidOperationException">The enumerator is positioned before the first element of the collection or after the last element.</exception>
    Public ReadOnly Property Current As Object Implements System.Collections.IEnumerator.Current
        Get
            Return _file(_rowIndex)
        End Get
    End Property

    ''' <summary>
    ''' Advances the enumerator to the next element of the collection.
    ''' </summary>
    ''' <returns>
    ''' true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
    ''' </returns>
    ''' <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
    Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext
        _rowIndex += 1
        Return _rowIndex < _file.RecordCount
    End Function

    ''' <summary>
    ''' Sets the enumerator to its initial position, which is before the first element in the collection.
    ''' </summary>
    ''' <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
    Public Sub Reset() Implements System.Collections.IEnumerator.Reset
        _rowIndex = -1
    End Sub

End Class
